package com.pride1952.myoptimusx3;


import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;


/**
 * A simple {@link Fragment} subclass.
 */
public class LoginFragment extends Fragment {

    View mView;

    private EditText mEditUserName;
    private EditText mEditPsw;
    private Button mBtnLogin;
    private TextView mTxtForgetPsw;
    private ImageButton mImgBtnLoginQQ;
    private ImageButton mImgBtnLoginWeChat;
    private ImageButton mImgBtnLoginWeibo;

    public LoginFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        mView=inflater.inflate(R.layout.fragment_login, container, false);
        initWidgets();
        return mView;
    }

    private void initWidgets(){
        mEditUserName=(EditText)mView.findViewById(R.id.edit_signin_username);
        mEditPsw=(EditText)mView.findViewById(R.id.edit_signin_psw);
        mBtnLogin=(Button)mView.findViewById(R.id.btn_signin_signin);
        mBtnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences mPreferences=getActivity().getSharedPreferences("isLogin", getActivity().MODE_PRIVATE);
                SharedPreferences.Editor mEditor=mPreferences.edit();
                mEditor.putBoolean("isLogin",true);
                mEditor.commit();
                Intent intent = new Intent();
                intent.setClass(getActivity(), MainActivity.class);
                startActivity(intent);
                getActivity().finish();
            }
        });
        mTxtForgetPsw=(TextView)mView.findViewById(R.id.txt_forget_psw);
        mTxtForgetPsw.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //todo 忘记密码
            }
        });
        mImgBtnLoginQQ=(ImageButton)mView.findViewById(R.id.imgbtn_login_qq);
        mImgBtnLoginQQ.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //todo qq登陆
            }
        });
        mImgBtnLoginWeChat=(ImageButton)mView.findViewById(R.id.imgbtn_login_wechat);
        mImgBtnLoginWeChat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //todo 微信登陆
            }
        });
        mImgBtnLoginWeibo=(ImageButton)mView.findViewById(R.id.imgbtn_login_weibo);
        mImgBtnLoginWeibo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //todo 微博登陆
            }
        });
    }
}
